﻿

using System.Data;
using System.Data.SqlClient;

namespace ybx_caller.entity
{
    public  class GetDataFromRis
    {
        public static DataTable QueryDatabase(string b,string e)
        {
            string connectionString = "Server=192.168.131.122;Database=digitlab;User Id=ywc;Password=Thyy1234;";
            string query = @"SELECT 
                            '420300' area_code,
                            'SYSTHYY' enterprise_id,
                            '3' check_type,
                            CONVERT(VARCHAR(10),check_date) service_date,
                            COUNT(1)  quantity
                            FROM  HuRen_ReportForm 
                            WHERE   check_date >= @b
                            AND check_date <= @e
                            GROUP BY CONVERT(VARCHAR(10),check_date)";
            DataTable dataTable = new DataTable();
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(query, connection);
                SqlParameter[] parameters = new SqlParameter[]
                {
                    new SqlParameter("@b", SqlDbType.VarChar) { Value = b+" 00:00:00" },
                    new SqlParameter("@e", SqlDbType.VarChar) { Value = e+" 23:59:59" }
                };
                command.Parameters.AddRange(parameters);
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    dataTable.Load(reader);
                }
            }
            return dataTable;
        }
    }
}
